//
//  AIFFastRegisterManager.m
//  PywSdk
//
//  Created by smallwave on 16/9/22.
//  Copyright © 2016年 zero. All rights reserved.
//

#import "AIFFastRegisterManager.h"
#import "PywRSAUtil.h"

@implementation AIFFastRegisterManager

NSString *const FastRegister_TID = @"tid";
NSString *const FastRegister_GAMEID = @"gameid";
NSString *const FastRegister_FLAG = @"flag";
NSString *const FastRegister_SIGN = @"sign";
NSString *const FastRegister_ACCOUNT = @"account";
NSString *const FastRegister_PASSWORD = @"password";

- (instancetype)init
{
    self = [super init];
    if (self) {
        self.child = self;
        self.paramSource = self;
        self.validate = self;
    }
    return self;
}

#pragma mark - ETAPIManager
- (NSString *)methodName{
    return URL_FASTREGISTER;
}

- (ETAPIManagerRequestType)requestType{
    return ETAPIManagerRequestTypePost;
}


- (NSString *)seriviceType{
    return [PywAppInfo sharedAppInfo].seriviceType;
}

#pragma mark - ETAPIManagerParamSourceDelegate

- (NSDictionary *)paramsForApi:(ETApiBaseManager *)manager{
    
    //流水号
    NSString *gameid = [PywAppInfo sharedAppInfo].gameId;
    
    NSString *tid = [[PywAppInfo sharedAppInfo] tid];
    NSString *apiSecret2 = [AppUtil getApiSecret2:tid apiSecret:[PywAppInfo sharedAppInfo].apisecret];
    NSString *sign = [NSString stringWithFormat:@"%@%@",gameid,apiSecret2];
    sign = [PywCipherUtils md5:sign];
    
    NSString *flag = [NSString stringWithFormat:@"%d",self.flag];
    
    MutableDictionary *param = [[MutableDictionary alloc] init];
    if (self.flag == FastRegisterFlag_Login) {
        NSString *account = self.account;
        NSString *password = [PywRSAUtil encryptString:self.password];
        [param setObject:account forKey:FastRegister_ACCOUNT];
        [param setObject:password forKey:FastRegister_PASSWORD];
    }
    [param setObject:tid forKey:FastRegister_TID];
    [param setObject:gameid forKey:FastRegister_GAMEID];
    [param setObject:sign forKey:FastRegister_SIGN];
    [param setObject:flag forKey:FastRegister_FLAG];
    return param;
}

#pragma mark - ETAPIManagerValidator
- (BOOL)manager:(ETApiBaseManager *)manager isCorrectWithParamsData:(NSDictionary *)data{
    return YES;
}

- (BOOL)manager:(ETApiBaseManager *)manager isCorrectWithCallBackData:(NSDictionary *)data{
    return YES;
}

@end
